import { GAME_CONFIG } from './game-config.js';

/**
 * 游戏状态管理类
 * @description 负责管理游戏的所有状态信息
 */
export class GameState {
    constructor() {
        this.reset();
    }

    /**
     * 重置游戏状态
     */
    reset() {
        this.score = GAME_CONFIG.GAME.INITIAL_SCORE;
        this.distance = 0;
        this.level = GAME_CONFIG.GAME.INITIAL_LEVEL;
        this.speed = 0;
        this.maxSpeed = 0;
        this.gameRunning = true;
        this.paused = false;
    }

    /**
     * 更新距离和等级
     * @param {number} speed - 当前速度
     */
    updateDistance(speed) {
        this.distance += speed * 0.1;
        this.level = Math.floor(this.distance / GAME_CONFIG.GAME.LEVEL_DISTANCE) + 1;
    }

    /**
     * 更新最高速度
     * @param {number} speed - 当前速度
     */
    updateMaxSpeed(speed) {
        if (speed > this.maxSpeed) {
            this.maxSpeed = speed;
        }
    }

    /**
     * 增加分数
     * @param {number} points - 增加的分数
     */
    addScore(points) {
        this.score += points;
    }

    /**
     * 暂停/继续游戏
     */
    togglePause() {
        this.paused = !this.paused;
    }

    /**
     * 游戏结束
     */
    gameOver() {
        this.gameRunning = false;
    }

    /**
     * 获取游戏状态数据
     * @returns {Object} 游戏状态数据
     */
    getState() {
        return {
            score: Math.floor(this.score),
            distance: Math.floor(this.distance),
            level: this.level,
            speed: Math.floor(this.speed),
            maxSpeed: Math.floor(this.maxSpeed),
            gameRunning: this.gameRunning,
            paused: this.paused
        };
    }
} 